
var DeptInfoDlg = {
    data: {
        parentId: "",
        parentName: ""
    }
};



layui.use(['layer', 'form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    // 让当前iframe弹层高度适应
    //admin.iframeAuto();


    $('#parentName').click(function () {
    var formName = encodeURIComponent("parent.DeptInfoDlg.data.parentName");
    var formId = encodeURIComponent("parent.DeptInfoDlg.data.parentId");
    var treeUrl = encodeURIComponent(Sam.ctxPath+"/sam/dept/tree");

    layer.open({
        type: 2,
        title: '父级部门',
        area: ['350px', '400px'],
        content: Sam.ctxPath + '/sam/dept/openDeptTreeSelect?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
        end: function () {
            $("#parentId").val(DeptInfoDlg.data.parentId);
            $("#parentName").val(DeptInfoDlg.data.parentName);
        }
    });
  });



    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var path_ = "/sam/dept/add.json";
        if(data.field.id!=''){
            path_ = "/sam/dept/edit.json";
        }
        var ajax = new $ax(Sam.ctxPath + path_, function (data) {
            Sam.success("保存成功！");
            admin.putTempData('formOk', true);
            admin.closeThisDialog();
        }, function (data) {
            Sam.error("保存失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
    });
});